#include "parallel.h"
static double sum[MAX_THREADS];

int pi_parallel_area(const int thread){ 
    double x, pi; 
    step = 1.0 / (double)num_steps; 
    #pragma omp parallel
    {
        double x;
        int id = omp_get_thread_num();
        sum[id] = 0.0;
        for (int i=1; i < num_steps; i+=thread) { 
            x = (i-0.5)*step; 
            sum[id] += 4.0/(1.0+x*x);
        } 
    }

    for(int i=0;i<thread;i++) pi += sum[i] * step;
    printf("pi = %.20lf\n",pi);

}

int main(int argc, char **argv){
    for(int i = 0; i < 9; i++){
        double start, end; 
        int thread = threads[i]; 
        omp_set_num_threads(thread);
        start = omp_get_wtime(); 
        pi_parallel_area(thread);
        end = omp_get_wtime(); 
        printf("thread %d Work took %f seconds\n",thread, end - start);
    }
}